﻿using BSChuangXu.API.Read.Appicant.Commend.MenuCommend;
using BSChuangXu.Domain.User;
using BSChuangXu.ErrorCode;
using BSChuangXu.Infrastructure.Interface;
using MediatR;

namespace BSChuangXu.API.Read.Appicant.CommendHandel.MenuCommandHandler
{
    /// <summary>
    /// 菜单列表显示
    /// </summary>
    public class GetMenuNameCommandHandler : IRequestHandler<GetMenuNameCommend, APIResult<List<MenuModel>>>
    {
        private readonly IBaseRepository<MenuModel> menuRepos;

        public GetMenuNameCommandHandler(IBaseRepository<MenuModel> menuRepos)
        {
            this.menuRepos = menuRepos;
        }
        /// <summary>
        /// 菜单列表显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<List<MenuModel>>> Handle(GetMenuNameCommend request, CancellationToken cancellationToken)
        {
            APIResult<List<MenuModel>>  result = new APIResult<List<MenuModel>>();
            var list = menuRepos.GetAll().Result;
            result.data = list.ToList();
            return await Task.FromResult(result);
        }
    }
}
